<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>权限管理页面</title>
<%@ include file="../include/easyui.jsp"%>
</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">
	<div data-options="region:'west',split:true,border:false,title:'菜单列表'"  style="width: 200px">
		<table id="menuDg"></table>
    </div>   
    <div data-options="region:'center',split:true,border:false,title:'权限列表'">
		<shiro:hasRole name="superAdmin">
			<div id="toolbar" style="padding:5px;height:auto">
				<div>
					<shiro:hasPermission name="system:permission:add">
						<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="add()">添加</a>
						<span class="toolbar-item dialog-tool-separator"></span>
					</shiro:hasPermission>
					<shiro:hasPermission name="system:permission:add">
						<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-remove" onclick="del()">删除</a>
						<span class="toolbar-item dialog-tool-separator"></span>
					</shiro:hasPermission>
					<shiro:hasPermission name="system:permission:add">
						<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="update()">修改</a>
					</shiro:hasPermission>
				</div>
			</div>
		</shiro:hasRole>
    	<table id="dg"></table>
    </div>   
<div id="dlg"></div>

<script type="text/javascript">
var dg;
var dialog;
var menuDg;
var pid;
$(function(){   
	menuDg=$('#menuDg').treegrid({  
		method: "get",
		url:'${ctx}/system/menu/list',
		fit : true,
		fitColumns : true,
		border : false,
		idField : 'id',
		treeField:'name',
		parentField : 'parentId',
		iconCls: 'icon',
		animate:true,
		rownumbers:false,
		singleSelect:true,
		striped:true,
		columns:[[
			{field:'id',title:'id',hidden:true},
			{field:'name',title:'名称',width:100}
		]],
		enableHeaderClickMenu: false,
		enableHeaderContextMenu: false,
		enableRowContextMenu: false,
		dataPlain: true,
		onClickRow:function(rowData){
			pid=rowData.id;
			dg.datagrid('reload',{parentId:pid});
		}
	});
	
	dg=$('#dg').datagrid({   
		method: "get",
		url:'${ctx}/system/permission/list',
		fit : true,
		fitColumns : true,
		border : false,
		idField : 'id',
		treeField:'name',
		parentField : 'parentId',
		iconCls: 'icon',
		animate:true,
		rownumbers:true,
		singleSelect:true,
		striped:true,//隔行变色
		columns:[[
			{field:'id',title:'id',hidden:true,width:100},
			{field:'name',title:'名称',width:100},
			{field:'code',title:'权限编码',width:135},
			{field:'url',title:'请求路径',width:135},
			{field:'sort',title:'排序',width:30},
			{field:'description',title:'描述',width:100},
			{field:'updateTime',title:'更新时间',sortable:true,width:130,formatter:formatterdateAll},
		]],
		toolbar:'#toolbar',
		dataPlain: true
	});
});

//弹窗增加
function add() {
	dialog=$('#dlg').dialog({
	    title: '添加权限',    
	    width: 450,    
	    height: 300,    
	    closed: false,    
	    cache: false,
	    maximizable:true,
	    resizable:true,
	    href:'${ctx}/system/permission/addForm',
	    modal: true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
				dialog.panel('close');
			}
		}]
	});
}

//删除
function del(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) {
		return;
	}
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/system/permission/delete/"+row.id,
				success: function(data){
					successTip(data.message,dg);
				}
			});
		} 
	});
}

//修改
function update(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	dialog=$("#dlg").dialog({
	    title: '修改权限',    
	    width: 450,    
	    height: 300,    
	    href:'${ctx}/system/permission/updateForm/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
				dialog.panel('close');
			}
		}]
	});
}
</script>
</body>
</html>